var $,
    form,
    loc = location.href,
    n1 = loc.length,//地址的总长度
    n2 = loc.indexOf('='),//取得=号的位置
    id = decodeURI(loc.substr(n2 + 1, n1 - n2));

var user = JSON.parse(localStorage.getItem("user"));

var originalpriceProduct;
layui.use(['jquery', 'form'], function () {
    $ = layui.jquery;
    form = layui.form;
    $.ajax({
        url:'/Product/getByIdProduct',
        dataType: 'json',
        data: {
            'productId' : id
        },
        success: function (item) {
            $('input[name=productCode]').val(item.data.productCode);
            $('input[name=productName]').val(item.data.productName);
            $('input[name=currentpriceProduct]').val(item.data.currentpriceProduct);
            originalpriceProduct = item.data.currentpriceProduct;
            $('#proTitle').text(item.data.productSate);
            console.log($('#proTitle').text());
            $('textarea[name=productLabel]').val(item.data.productLabel);
            $('textarea[name=productDescription]').val(item.data.productDescription);
        }
    });
});


//确定
function determine() {
    var data = form.val('formTest');
    var date = parent.getDate()
    $.ajax({
        url: '/Product/updateProduct',
        dataType: 'json',
        data: {
            'productId': id,
            'productCode': data.productCode,
            'productName': data.productName,
            'currentpriceProduct': data.currentpriceProduct,
            'productLabel': data.productLabel,
            'productDescription': data.productDescription,
            "updateId": user.userId,
            "updateDate": date,
            "originalpriceProduct": originalpriceProduct,
            'courseId': id,
            'courseName': data.productName,
            'courseStatus': 2,
            'courseCstatus': 3,
            'userId': user.userId,
            'coursePrice': originalpriceProduct,
            'courseNprice': data.currentpriceProduct,
            'type': 1,
        },
        success: function (item) {
            if (item.data) {
                layer.msg("修改成功");
                parent.addProductOperationRecord(2, date, "修改商品信息");
                parent.getTableData();
                cancel();
            } else {
                layer.msg("修改失败");
            }
        }
    })
}

//关闭
function cancel() {
    var index = parent.layer.index;
    parent.layer.close(index);
}